package com.chuang.bootplus.config.email;

import cn.hutool.extra.mail.MailAccount;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;

/**
 * @description: TODO email config
 * @author nuo
 * @date 2022/10/11 7:21
 * @version 1.0
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "spring.mail")
public class EmailConfig {

    private String host;
    private String port;
    private String username;
    private String password;

    @Bean
    public MailAccount mailAccount() {
        return new MailAccount().setHost(host)
                .setPass(password)
                .setFrom(username)
                .setPort(Integer.valueOf(port))
                .setAuth(true)
                .setSslEnable(true)
                .setDebug(true)
                .setCharset(StandardCharsets.UTF_8);
    }

}